
<link rel="stylesheet" href="jquery/easyui/themes/default/easyui.css">
<link rel="stylesheet" href="jquery/easyui/themes/icon.css">
<body>

<script>
function qq(value,name){
        alert(value+":"+name)
}
</script>

<div style="width: 100%;height: 98%">
    <table id="easyui_datagrid_source_fac" style="border:1px solid blue" >

    </table>
    <span id="check_one_lable" style="font-size:10px">赋值给腿</span><input type="checkbox" id="check_one" />
</div>


<script src="https://upload.shinehao.com.cn/20180816150739jquery-1.8.3.min.js"></script>
<script src="https://upload.shinehao.com.cn/20180816145716jquery.easyui.min.js"></script>
<script src="https://upload.shinehao.com.cn/20180816151727easyui-lang-zh_CN.js"></script>
<script>
var material_source_type = window.parent.getMyUrlQueryString(window.location.href,"material_source_type");
var dom = window.parent.getMyUrlQueryString(window.location.href,"dom");
var ev = window.parent.getMyUrlQueryString(window.location.href,"ev");
var father = window.parent.getMyUrlQueryString(window.location.href,"father");
$(function(){
    /*alert(material_source_type);
    alert("圈".indexOf(material_source_type)>-1);*/
    if(material_source_type.indexOf("圈")>-1){
        $("#check_one").attr("checked",true);
    }else{
        $("#check_one").css("display","none");
        $("#check_one_lable").css("display","none");
    }
    
    $("body").bind("click",function(){
        $('#easyui_datagrid_source_fac').combogrid("showPanel");
    })
    $('#easyui_datagrid_source_fac').combogrid({
        mode:"remote",
        url:window.parent.serverUrl+"/createOrder/getFactoryTabChildList",
        queryParams: {
            material_factory: 1,
            material_type: material_source_type
        },
        idField: 'color',
        textField: 'colorDescription',
        columns:[[
            {field:'color',title:'色号'},
            {field:'colorDescription',title:'颜色描述'},
            {field:'materialCode',title:'物料代码'},
            {field:'materialType',title:'物料类型',hidden:true},
            {field:'defaultWarehouse',title:'所属'}
        ]],
        height:"10%",
        width:"80%",
        panelWidth:"100%",
        panelHeight:"88%",
        //rownumbers:true,
        fitColumns:true,
        pagination:false,
        loadMsg:"加载中,请等待...",
        singleSelect:true,
        align:"center",
        //toolbar: '#easyui_datagrid_source_fac_tool',
        loadFilter: function(data){
          return data.data;  
        },
        keyHandler: {
            enter: function(e){
                //console.info($('#easyui_datagrid_source_fac').combogrid("getValue"));
                //console.info($('#easyui_datagrid_source_fac').combogrid("getText"));
                var rows = $('#easyui_datagrid_source_fac').combogrid('grid').datagrid('getData').rows;	// get datagrid object
                if(rows.length>0){
                    filldata(rows[0],"")
                }else{
                    filldata("",$('#easyui_datagrid_source_fac').combogrid("getText"))
                }
                $('#easyui_datagrid_source_fac').combogrid("showPanel");
            },
            query: function (q) {
                $('#easyui_datagrid_source_fac').combogrid("grid").datagrid("reload", {
                    material_factory: 1,
                    material_type: material_source_type,
                    'q': q,
                });
                $('#easyui_datagrid_source_fac').combogrid("setValue",q);
            },
            up: function (e) {
                
            },
            down: function (e) {
                
            }
        },
        onLoadSuccess:function(data){
            if(data.total > 0) {
                $("input[type='text']").focus();
                return;
            }  
            //$(this).datagrid('appendRow', { color: '<div style="text-align:center;color:red">没有相关记录！</div>' }).datagrid('mergeCells', { index: 0, field: 'color', colspan: 3});  
            $("input[type='text']").focus();
            $('#easyui_datagrid_source_fac').combogrid("showPanel");
        },
        /*onSelect:function(index,row){
            console.info(row);
            var self = $(window.parent.document).find("["+dom.split(":")[0]+"='"+dom.split(":")[1]+"']");
            //console.info("myid:"+$(self).attr("myid")+":"+$(self).length+":"+"'"+dom.split(":")[0]+"'");
            //console.info("id:"+$(self).attr("id")+":"+$(self).length+":"+"'"+dom.split(":")[0]+"'");
            //console.info($(self).attr("'"+dom.split(":")[0]+"'"));
            //物料代码 色号 颜色描述 规格 填充
            
            $("input[type='text']").focus();
            $('#easyui_datagrid_source_fac').combogrid("showPanel");
        },*/
        onClickRow:function(index,row){
            filldata(row,"");
            $("input[type='text']").focus();
            $('#easyui_datagrid_source_fac').combogrid("showPanel");
        }
    });
    $('#easyui_datagrid_source_fac').combogrid("showPanel");
    $("input[type='text']").focus();
})
    
function filldata(data,text){
    var key = dom.split(":")[0];
    var val = dom.split(":")[1];
    //做复制功能
    var ischeck = $("#check_one").is(":checked");
    var source_type_arr = window.parent.tbsourcefactoryEvent.table_source_type_arr;
    var index_quan ;
    var index_tui  ;
    if(ischeck){
        index_quan = $.inArray(material_source_type,source_type_arr);
        index_tui  = $.inArray(material_source_type.replace("圈","腿"),source_type_arr);
        console.info(index_quan+":"+index_tui);
    }
    
    if(data!=null&&data!=""){
        //console.info(data);
        //code
        $($(window.parent.document).find("."+father).find("["+key+"='"+val+"']")).find("[name='order_s_material_code']").val(data.materialCode);
        //color
        $($(window.parent.document).find("."+father).find("["+key+"='"+val+"']")).find("[name='order_s_material_color']").text(data.color);
        //description
        $($(window.parent.document).find("."+father).find("["+key+"='"+val+"']")).find("[name='order_s_material_description']").text(data.colorDescription);
        //复制功能
        console.info(index_quan>index_tui)
        if(ischeck&index_tui>-1){
            if(index_quan>index_tui){
                //圈在后
                /*console.info($($(window.parent.document).find("."+father).find("["+key+"='"+val+"']")).prevAll());*/
                $($(window.parent.document).find("."+father).find("["+key+"='"+val+"']")).prevAll().eq(index_quan-index_tui-1).find("[name='order_s_material_code']").val(data.materialCode);
                
                $($(window.parent.document).find("."+father).find("["+key+"='"+val+"']")).prevAll().eq(index_quan-index_tui-1).find("[name='order_s_material_color']").text(data.color);
                
                $($(window.parent.document).find("."+father).find("["+key+"='"+val+"']")).prevAll().eq(index_quan-index_tui-1).find("[name='order_s_material_description']").text(data.colorDescription);
            }else{
                //圈在前
                /*console.info(index_tui-index_quan);
                console.info($($(window.parent.document).find("."+father).find("["+key+"='"+val+"']")).nextAll().eq(index_tui-index_quan).attr('"'+key+'"'));*/
                
                $($(window.parent.document).find("."+father).find("["+key+"='"+val+"']")).nextAll().eq(index_tui-index_quan-1).find("[name='order_s_material_code']").val(data.materialCode);
                
                $($(window.parent.document).find("."+father).find("["+key+"='"+val+"']")).nextAll().eq(index_tui-index_quan-1).find("[name='order_s_material_color']").text(data.color);
                
                $($(window.parent.document).find("."+father).find("["+key+"='"+val+"']")).nextAll().eq(index_tui-index_quan-1).find("[name='order_s_material_description']").text(data.colorDescription);
                
            }
        }
    }
    if(text!=null&&text!=""){
        //color赋值
        $($(window.parent.document).find("."+father).find("["+key+"='"+val+"']")).find("[name='"+ev+"']").text(text);
        //code clear
        $($(window.parent.document).find("."+father).find("["+key+"='"+val+"']")).find("[name='order_s_material_code']").val("");
        
        if(ischeck&index_tui>-1){
            if(index_quan>index_tui){
                //圈在后
                $($(window.parent.document).find("."+father).find("["+key+"='"+val+"']")).prevAll().eq(index_quan-index_tui-1).find("[name='"+ev+"']").text(text);

                $($(window.parent.document).find("."+father).find("["+key+"='"+val+"']")).prevAll().eq(index_quan-index_tui-1).find("[name='order_s_material_code']").val("");

            }else{
                //圈在前
                $($(window.parent.document).find("."+father).find("["+key+"='"+val+"']")).nextAll().eq(index_tui-index_quan-1).find("[name='"+ev+"']").text(text);

                $($(window.parent.document).find("."+father).find("["+key+"='"+val+"']")).nextAll().eq(index_tui-index_quan-1).find("[name='order_s_material_code']").val("");

            }
        }
    }
    
    window.parent.tbsourcefactoryEvent.destroydialog();
    
}

</script>
</body>


























